package com.kaiyiweitong.tongxing.other;


import android.support.v4.app.Fragment;
import android.util.Log;

import java.util.HashMap;
import java.util.Map;

public final class FragmentFactory {
    private static Map<Class, Fragment> map = new HashMap<>();

    //获取实例
    public static synchronized Fragment getInstance(Class<? extends Fragment> clazz) {
        //从集合里面获取
        Fragment fragment = map.get(clazz);
        if (fragment == null) {
            try {
                fragment = clazz.newInstance();
                //保存进集合
                map.put(clazz, fragment);
            } catch (Exception e) {
                Log.e("FragmentFactory",e.toString());
            }
        }
        return fragment;
    }

}